class Solution {
public:
    vector<vector<int>> rst;
    vector<int> tempRst;

    vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
        // sort(candidates.begin(), candidates.end());
        combinationSumStep(candidates, 0, target);
        return rst;
    }

    void combinationSumStep(vector<int>& candidates, int index, int target) {
        if(target == 0) {
            rst.push_back(tempRst);
            return;
        }

        if(target < 0){
            return;
        }

        for(int i = index; i < candidates.size(); ++i) {
            tempRst.push_back(candidates[i]);
            combinationSumStep(candidates, i, target - candidates[i]);
            tempRst.pop_back();
        }
    }
};